package Manager;

import Database.AccountDB;
import Entity.Account;
import java.util.ArrayList;

/**
 *
 * @author CONG
 */
public class AccountManager {

    private ArrayList<Account> listAcc;
    public AccountManager() {
        listAcc = new ArrayList<Account>();
    }

    public boolean addAccount(Account acc) {
        for (int i = 0; i < listAcc.size(); i++) {
            if (listAcc.get(i).getResgisterNo() == acc.getResgisterNo()) {
                return false;
            }
        }
        listAcc.add(acc);
        return true;
    }

    public boolean removeAccount(int index) {
        for (int i = 0; i < listAcc.size(); i++) {
            if (listAcc.get(i).getResgisterNo() == index) {
                listAcc.remove(index);
                return true;
            }
        }
        return false;
    }

    public boolean updateAccount(Account acc) {
        for (int i = 0; i < listAcc.size(); i++) {
            if (listAcc.get(i).getResgisterNo() == acc.getResgisterNo()) {
                listAcc.set(i, acc);
                return true;
            }
        }
        return false;
    }

    public int getSize() {
        return listAcc.size();
    }

    public Account getAccount(int index) {
        return listAcc.get(index);
    }
    public void getAccountList(ArrayList<Account> l){
        listAcc.clear();
        listAcc.addAll(l);
    }
}
